<template>
  <div class="content">
    <van-nav-bar title="商品详情"  left-arrow  @click-left="back"  fixed placeholder>
        <template #left>
            <img src="../../../assets/back.png" alt="" class="back">
        </template>
    </van-nav-bar>
    <van-swipe :autoplay="3000" class="swipe">
       <van-swipe-item v-for="(image, index) in images" :key="index">
        <img v-lazy="image"  class="img" />
        </van-swipe-item>
    </van-swipe>
    <div class="goods-info">
        <div class="price-info">
            <span class="price">￥{{price}}</span>
            <span>已售{{salesVolume}}</span>
        </div>
        <div class="name">{{name}}</div>
        <div class="sku-info">
            <div class="title">规格
                <div class="change"><span style="color:#FB2F22;">更换</span>  &nbsp;&gt;</div>
            </div>
            <div class="sku">
                <van-button class="btn" >{{sku.name}}</van-button>
            </div>
        </div>
    </div>
    <div class="other-info">
        <div class="category item">
            <span class="title">所属分类</span>
            <span class="value">{{category}}</span>
        </div>
        <div class="discountRate item">
            <span class="title">折扣</span>
            <span class="value">{{discountRate}}</span>
        </div>
        <div class="noDeliveryAreaNameString item">
            <span class="title">不包括地区</span>
            <span class="value">{{noDeliveryAreaNameString}}</span>
        </div>
        <div class="nonPostalAreaNameString item">
            <span class="title">不邮寄地区</span>
            <span class="value">{{nonPostalAreaNameString}}</span>
        </div>
    </div>
    <div class="detail">
        <div class="title">商品详情</div>
        <div class="detail-images">
            <img v-lazy="image"  class="img" v-for="(image, index) in detailImages" :key="index"/>
        </div>
    </div>
  </div>
</template>

<script>
import { goodsDetailBySupplierList} from "@/api/api";
export default {
    data(){
        return {
            shop_id:1,
            role:7,
            id:'',
            images:[],
            price:'',
            salesVolume:'',
            name:'',
            sku:[],
            category:'',
            discountRate:'',
            noDeliveryAreaNameString:'',
            nonPostalAreaNameString:'',
            detailImages:[],
        }
    },
    mounted(){
        this.goodsDetailBySupplierList(this.$route.query.goodsId);
    },
    methods:{
        back(){
            this.$router.go(-1)
        },
        goodsDetailBySupplierList(goodsId){
            goodsDetailBySupplierList({id:goodsId}).then(res=>{
                let {id,images,detail_images,price,salesVolume,name,sku,category,discountRate,noDeliveryAreaNameString,nonPostalAreaNameString} = res.data.data
                this.id = id
                this.images = images ? images.split(',') : ''
                this.price = price
                this.salesVolume = salesVolume || 0
                this.name = name
                this.sku = sku
                this.category = category
                this.discountRate = discountRate
                this.noDeliveryAreaNameString = noDeliveryAreaNameString
                this.nonPostalAreaNameString = nonPostalAreaNameString
                this.detailImages = detail_images? detail_images.split(','):''
            })

        }
    }
}
</script>

<style scoped>
.content {
    background-color: #f8f9f8;
}
.back {
    height: 22px;
}
.swipe {
    width: 100vw;
}
.swipe .img {
    display: block;
    width: 100%;
}
.goods-info{
    background-color: #fff;
    padding: 10px;
    font-size: 14px;
    color: #B7B8B6;
}


.goods-info .price-info{
    height: 35px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}
.goods-info .price-info .price{
    font-size: 20px;
    color: #FB2F22;
}

.goods-info .name {
    padding: 15px 0;
    font-size: 16px;
    font-weight: 700;
    color: #000;
    border-bottom: 1px solid #eee;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}


.sku-info .title{
    position: relative;
    line-height: 50px;
}
.sku-info .title .change{
    position: absolute;
    top: 0;
    right: 0;
}
.sku-info .sku .btn {
    background-color: #f8f8f8;
    border-radius: 5px;
}



.other-info {
    padding: 10px;
    font-size: 14px;
    background-color: #fff;
    margin-top: 10px;
}
.other-info .item {
    line-height: 30px;
}
.other-info .title {
    display: inline-block;
    color: #B7B8B6;
    width: 80px;
    text-align: justify;
    text-align-last: justify;
    margin-right: 15px;
}

.detail {
    margin-top: 20px;
    background-color: #fff;
}
.detail .title{
    position: relative;
    padding: 15px;
    text-align: center;
    font-size: 16px;
    border-bottom: 1px solid #eee;
    font-weight: 700;
}
.detail .title::after{
    content: '';
    position: absolute;
    bottom: 0px;
    left: 50%;
    transform: translateX(-50%);
    width: 65px;
    height: 2px;
    background-color: #000;
}
.detail-images .img {
    display: block;
    width: 100%;
}
</style>